package com.ncp.model.biz.index;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.ncp.model.dao.DbConnection;
import com.ncp.model.entity.index.IntroBean;

public class IntroManager {
	private Connection ct=null;
	private PreparedStatement ps=null;
	private ResultSet rs=null;
	////从数据库取出介绍信息
	public IntroBean getInfo(){
		IntroBean ib=new IntroBean();
		try {
			ct = DbConnection.getConnByDataSource();
			String sql="select * from INTRO where INTROID=1";
			ps=ct.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				ib.setId(rs.getInt(1));
				ib.setContent(rs.getString(2));
				ib.setPicture(rs.getString(3));
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			this.closeResource();
		}
		return ib;
	}
	//向数据库插入/编辑介绍信息
	public boolean updateIntro(String content,String picture){
		boolean b=false;
		try {
			ct = DbConnection.getConnByDataSource();
			String sql="update INTRO set content='"+content+"',picture='"+picture+"' where INTROID=1";
			ps=ct.prepareStatement(sql);
			int num=ps.executeUpdate();
			if(num==1){
				b=true;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			this.closeResource();
		}
		return b;
	}
	//关闭资源
	public void closeResource(){
		try {
			if(rs!=null){
				rs.close();
				rs=null;
			}
			if(ps!=null){
				ps.close();
				ps=null;
			}
			if(ct!=null){
				ct.close();
				ct=null;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
